<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="demo">
    <h2>显示格式化日期时间</h2>
    <p>{{time}}</p>
    <p>最完整的：{{time | dateString}}</p>
    <p>年月日：{{time | dateString('YYYY-MM-DD')}}</p>
  </div>
  
  <script type="text/javascript" src="../vue.js"></script>
  <script type="text/javascript" src="https://cdn.bootcss.com/moment.js/2.22.1/moment.js"></script>
  <script>
    Vue.filters('dateString', function(value, format="YYYY-MM-DD HH:mm:ss"){
      return moment(value).format(format)
    })
    new Vue({
      el: '#demo',
      data: {
        time: new Date()
      },
      mounted() {
        setInterval(() => {
          this.time = new Date()
        }, 1000)
      }
    })
  </script>

</body>
</html>